/* global shoproot */

/**
 * Desc
 * @description Holp You Do Good But Not Evil
 * @copyright   Copyright 2014-2015 <ycchen@iwshop.cn>
 * @license     LGPL (http://www.gnu.org/licenses/lgpl.html)
 * @author      Chenyong Cai <ycchen@iwshop.cn>
 * @package     Wshop
 * @link        http://www.iwshop.cn
 */

requirejs(['jquery', 'util', 'datatables', 'Spinner','WdatePicker','datetimepicker','xdate'], function ($, util,  dataTables, Spinner,WdatePicker,xdate) {
	 function init_time_picker(){
	     	$.datetimepicker.setLocale('zh');
	         $('#search_start').datetimepicker({
	             format: 'Y-m-d'
	         });
	     }
	
	$(document).ready(function() {
		
		init_time_picker();
		var firstDate = new Date();
		var currentDate = new XDate(firstDate).toString('yyyy-MM-dd');
		if(currentDate == ''){
			$('#search_start').val(currentDate);
		}
	});

	

	
    $('#save_btn').click(function () {
    	
    	var online_money = $('#online_money').val();
    	var offline_money = $('#offline_money').val();
    	var id = $('#numId').val();
    	var des = $('#des').val();
    	var search_start = $('#search_start').val();
    	
 
    	$('#save_btn').attr("disabled",true);
        $.post('?/InCome/ajax_save/', {
        	id:id,
        	online_money: online_money,
        	offline_money: offline_money,
        	des: des,
        	time:search_start
 
        }, function (r) {
  
        	$('#save_btn').removeAttr('disabled');
            if (r > 0) {     
                    $('#save_btn').attr('data-id', r);
                    $("input").attr("value","");
                    $("textarea").attr("value","");
                    util.Alert('保存成功');
               
            } else {
                util.Alert('操作失败', true);
            }
        });
    });
});